package com.yida.gwj.deposit.controller;

import com.yida.common.core.constant.SecurityConstants;
import com.yida.common.core.domain.R;
import com.yida.common.core.enums.UserStatus;
import com.yida.common.core.text.Convert;
import com.yida.common.core.utils.CheckRemoteServiceResultUtils;
import com.yida.common.core.utils.StringUtils;
import com.yida.common.core.utils.file.FileTypeUtils;
import com.yida.common.core.utils.poi.ExcelUtil;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.gwj.api.domain.GwjConfBusinessFlag;
import com.yida.gwj.api.domain.GwjConfStep;
import com.yida.gwj.api.domain.GwjFinanceMoney;
import com.yida.gwj.api.domain.request.RemoteGwjFinanceAccountDetailRequest;
import com.yida.gwj.api.domain.request.RemoteGwjFinanceAccountMainRequest;
import com.yida.gwj.api.service.RemoteGwjConfigService;
import com.yida.gwj.api.service.RemoteGwjFinanceService;
import com.yida.gwj.common.constant.GwjConstants;
import com.yida.gwj.common.domain.dto.GwjBusinessFlagDTO;
import com.yida.gwj.common.domain.dto.GwjBusinessStepDTO;
import com.yida.gwj.common.enums.GwjBusinessFlagType;
import com.yida.gwj.common.utils.GwjConvertUtil;
import com.yida.gwj.deposit.domain.GwjDepositBusiness;
import com.yida.gwj.deposit.domain.GwjDepositBusinessBuild;
import com.yida.gwj.deposit.domain.GwjDepositBusinessCommunity;
import com.yida.gwj.deposit.domain.GwjDepositBusinessHouse;
import com.yida.gwj.deposit.domain.dto.GwjBusinessLogDTO;
import com.yida.gwj.deposit.domain.dto.GwjPublicBusinessBuildDTO;
import com.yida.gwj.deposit.domain.dto.split.*;
import com.yida.gwj.deposit.domain.request.*;
import com.yida.gwj.deposit.domain.request.split.*;
import com.yida.gwj.deposit.domain.vo.GwjDepositBusinessHouseExcelVo;
import com.yida.gwj.deposit.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 业务（维修资金分户（初始化））Controller
 *
 * @author lqq
 * @date 2023-01-09
 */
@RestController
@RequestMapping("/fundsSplit")
@Api(tags = "维修资金分户（初始化）")
public class GwjFundsSplitBusinessController extends BaseController {

    @Resource
    private IGwjDepositBusinessService gwjDepositBusinessService;

    @Resource
    private IGwjFundsSplitBusinessService gwjFundsSplitBusinessService;

    @Resource
    private IGwjDepositBusinessCommunityService gwjDepositBusinessCommunityService;

    @Resource
    private IGwjDepositBusinessBuildService gwjDepositBusinessBuildService;

    @Resource
    private IGwjDepositBusinessHouseService gwjDepositBusinessHouseService;

    @Resource
    private IGwjDepositBusinessLogService gwjDepositBusinessLogService;

    @Resource
    private IGwjDepositBusinessMoneyService gwjDepositBusinessMoneyService;

    @Resource
    private IGwjDepositBusinessDetailService gwjDepositBusinessDetailService;

    @Resource
    private RemoteGwjConfigService remoteGwjConfigService;

    @Resource
    private RemoteGwjFinanceService remoteGwjFinanceService;

    @GetMapping("/list")
    @RequiresPermissions("gwj:deposit:fundsSplit:list")
    @ApiOperation("查询业务列表")
    public TableDataInfo list(GwjFundsSplitBusinessQueryRequest request) {
        GwjDepositBusiness gwjDepositBusiness = GwjConvertUtil.convert(request, GwjDepositBusiness.class);
        gwjDepositBusiness.setBizFlagId(GwjBusinessFlagType.FUNDS_SPLIT.getCode());
        startPage();
        List<GwjDepositBusiness> list = gwjDepositBusinessService.selectGwjDepositBusinessList(gwjDepositBusiness);
        return GwjConvertUtil.convertTable(getDataTable(list), GwjFundsSplitBusinessDTO.class);
    }

    @GetMapping("/info")
    @RequiresPermissions("gwj:deposit:fundsSplit:list")
    @ApiOperation("查询业务流程步骤")
    public AjaxResult getBusinessInfo() {
        AjaxResult ajax = AjaxResult.success();
        R<GwjConfBusinessFlag> gwjConfBusinessFlagR = remoteGwjConfigService.selectGwjConfBusinessFlagByBizFlagId(GwjBusinessFlagType.FUNDS_SPLIT.getCode(), SecurityConstants.INNER);
        if (CheckRemoteServiceResultUtils.isSuccessWithData(gwjConfBusinessFlagR)) {
            ajax.put("bizFlag", GwjConvertUtil.convert(gwjConfBusinessFlagR.getData(), GwjBusinessFlagDTO.class));
        }
        R<List<GwjConfStep>> gwjConfStepsR = remoteGwjConfigService.selectGwjConfStepListByFlagId(GwjBusinessFlagType.FUNDS_SPLIT.getCode(), SecurityConstants.INNER);
        if (CheckRemoteServiceResultUtils.isSuccessWithData(gwjConfStepsR)) {
            List<GwjBusinessStepDTO> steps = GwjConvertUtil.convertList(gwjConfStepsR.getData(), GwjBusinessStepDTO.class);
            steps.forEach(stepDTO -> {
                R<List<String>> listR = remoteGwjConfigService.selectGwjConfStepConfigInfoCodeListByBizFlagId(stepDTO.getStepId(), SecurityConstants.INNER);
                if (CheckRemoteServiceResultUtils.isSuccessWithData(listR)) {
                    stepDTO.setConfigs(listR.getData());
                }
            });
            ajax.put("steps", steps);
        }

        return ajax;
    }

    @PostMapping("/send")
    @RequiresPermissions("gwj:deposit:fundsSplit:send")
    @Log(title = "维修资金分户（初始化）-送件（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("送件")
    public AjaxResult sendBusiness(@Validated(GwjDepositBusinessLogRequest.Send.class) @RequestBody GwjDepositBusinessLogRequest request) {
        gwjDepositBusinessService.send(request);
        return AjaxResult.success();
    }

    @DeleteMapping("/fallback")
    @RequiresPermissions("gwj:deposit:fundsSplit:fallback")
    @Log(title = "维修资金分户（初始化）-回退（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("回退")
    public AjaxResult fallback(@Validated(GwjDepositBusinessLogRequest.Fallback.class) @RequestBody GwjDepositBusinessLogRequest request) {
        gwjDepositBusinessService.fallback(request);
        return AjaxResult.success();
    }

    @PostMapping("/signOpinion")
    @RequiresPermissions("gwj:deposit:fundsSplit:signOpinion")
    @Log(title = "维修资金分户（初始化）-签署意见（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("签署意见")
    public AjaxResult signOpinion(@Validated(GwjDepositBusinessLogRequest.Sign.class) @RequestBody GwjDepositBusinessLogRequest request) {
        gwjDepositBusinessService.signOpinion(request);
        return AjaxResult.success();
    }

    @GetMapping("/flow")
    @RequiresPermissions("gwj:deposit:fundsSplit:log")
    @ApiOperation("查看业务流程")
    public AjaxResult flow(Long bizId) {
        return AjaxResult.success(gwjDepositBusinessService.getBusinessFlow(bizId, GwjBusinessFlagType.FUNDS_SPLIT.getCode()));
    }

    @GetMapping("/log/{bizId}")
    @RequiresPermissions("gwj:deposit:fundsSplit:log")
    @ApiOperation("查看业务日志")
    public AjaxResult log(@PathVariable Long bizId) {
        return AjaxResult.success(GwjConvertUtil.convertList(gwjDepositBusinessLogService.selectGwjDepositBusinessLogListByBizId(bizId), GwjBusinessLogDTO.class));
    }

    @RequiresPermissions("gwj:deposit:fundsSplit:save")
    @PostMapping("/save")
    @Log(title = "维修资金分户（初始化）-保存（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("保存")
    public AjaxResult save(@Validated(GwjFundsSplitSaveSubmitRequest.Save.class) @RequestBody GwjFundsSplitSaveSubmitRequest request) {
        return AjaxResult.success(gwjFundsSplitBusinessService.saveBusiness(request));
    }

    @RequiresPermissions("gwj:deposit:fundsSplit:save")
    @PutMapping("/update")
    @Log(title = "维修资金分户（初始化）-二次保存（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("二次保存")
    public AjaxResult update(@Validated(GwjFundsSplitSaveSubmitRequest.Update.class) @RequestBody GwjFundsSplitSaveSubmitRequest request) {
        gwjFundsSplitBusinessService.updateBusiness(request);
        return AjaxResult.success();
    }

    @RequiresPermissions("gwj:deposit:fundsSplit:submit")
    @PostMapping("/submit")
    @Log(title = "维修资金分户（初始化）-提交（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("提交")
    public AjaxResult submit(@Validated @RequestBody GwjFundsSplitSaveSubmitRequest request) {
        gwjFundsSplitBusinessService.submitBusiness(request);
        return AjaxResult.success();
    }

    @GetMapping("/houseMaintain/confirm/{bizId}/{bizHouseIds}")
    @Log(title = "维修资金分户（初始化）-房屋维护-加入选择（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("房屋维护-加入选择")
    public AjaxResult houseMaintainConfirmSelect(@PathVariable("bizHouseIds") Long[] bizHouseIds, @PathVariable("bizId") Long bizId) {
        gwjFundsSplitBusinessService.houseMaintainConfirmSelect(bizHouseIds, bizId);
        return AjaxResult.success();
    }

    @GetMapping("/houseMaintain/cancel/{bizId}/{bizHouseIds}")
    @Log(title = "维修资金分户（初始化）-房屋维护-取消选择（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("房屋维护-取消选择")
    public AjaxResult houseMaintainCancelSelect(@PathVariable("bizHouseIds") Long[] bizHouseIds, @PathVariable("bizId") Long bizId) {
        gwjFundsSplitBusinessService.houseMaintainCancelSelect(bizHouseIds, bizId);
        return AjaxResult.success();
    }

    @PostMapping("/moneyMaintain/list")
    @ApiOperation("金额维护-列表")
    public TableDataInfo moneyMaintainList(@RequestBody GwjFinanceMoney financeMoney) {
        //moneyIds为空说明查询未删除的、未选择的
        if (StringUtils.isEmpty(financeMoney.getMoneyIds())) {
            financeMoney.setDelFlag(UserStatus.OK.getCode());
            financeMoney.setSelectFlag(GwjConstants.NO);
        }
        startPage();
        List<GwjFinanceMoney> list = remoteGwjFinanceService.selectFinanceMoneyList(financeMoney, SecurityConstants.INNER).getData();
        return getDataTable(list);
    }

    @GetMapping("/moneyMaintain/confirm/{bizId}/{moneyIds}")
    @Log(title = "维修资金分户（初始化）-金额维护-加入选择|资金分户-添加（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("金额维护-加入选择")
    public AjaxResult financeMoneyConfirmSelect(@PathVariable("moneyIds") Long[] moneyIds, @PathVariable("bizId") Long bizId) {
        gwjFundsSplitBusinessService.moneyMaintainConfirmSelect(moneyIds, bizId);
        return AjaxResult.success();
    }

    @GetMapping("/moneyMaintain/cancel/{bizId}/{moneyIds}")
    @Log(title = "维修资金分户（初始化）-金额维护-取消选择|资金分户-删除（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("金额维护-取消选择")
    public AjaxResult financeMoneyCancelSelect(@PathVariable("moneyIds") Long[] moneyIds, @PathVariable("bizId") Long bizId) {
        gwjFundsSplitBusinessService.moneyMaintainCancelSelect(moneyIds, bizId);
        return AjaxResult.success();
    }

    @DeleteMapping("/deleteBusinessData/{bizId}")
    @Log(title = "维修资金分户（初始化）-删页（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("删页")
    public AjaxResult deleteBusinessData(@PathVariable Long bizId) {
        gwjFundsSplitBusinessService.deleteBusinessData(bizId);
        return AjaxResult.success();
    }

    @DeleteMapping("/invalidBusiness")
    @Log(title = "维修资金分户（初始化）-业务作废（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("业务作废")
    public AjaxResult invalidBusiness(@Validated(GwjDepositBusinessLogRequest.Cancellation.class) @RequestBody GwjDepositBusinessLogRequest request) {
        gwjDepositBusinessService.invalidBusiness(request);
        return AjaxResult.success();
    }

    @DeleteMapping("/deleteBuildData/{bizId}/{bizBuildIds}")
    @Log(title = "维修资金分户（初始化）-删除楼栋（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("删除楼栋")
    public AjaxResult deleteBuild(@PathVariable("bizId") Long bizId, @PathVariable("bizBuildIds") Long[] bizBuildIds) {
        gwjFundsSplitBusinessService.deleteBuildData(bizId, bizBuildIds);
        return AjaxResult.success();
    }

    @GetMapping("/importBuild/{bizId}/{buildIds}")
    @Log(title = "维修资金分户（初始化）-导入楼栋（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("导入楼栋")
    public AjaxResult importBuild(@PathVariable("bizId") Long bizId, @PathVariable("buildIds") Long[] buildIds) {
        gwjFundsSplitBusinessService.importBuild(bizId, buildIds);
        return AjaxResult.success();
    }

    @PostMapping("/importCommunity")
    @Log(title = "维修资金分户（初始化）-导入小区（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("导入小区（切换小区）")
    public AjaxResult importCommunity(@Validated @RequestBody GwjFundsSplitBusinessCommunityRequest request) {
        GwjDepositBusinessCommunity gwjDepositBusinessCommunity = GwjConvertUtil.convert(request, GwjDepositBusinessCommunity.class);
        gwjFundsSplitBusinessService.importCommunity(gwjDepositBusinessCommunity);
        return AjaxResult.success();
    }

    @GetMapping("/caseInfo/{bizId}")
    @RequiresPermissions("gwj:deposit:fundsSplit:list")
    @ApiOperation("案例信息")
    public AjaxResult caseInfo(@PathVariable Long bizId) {
        return AjaxResult.success(GwjConvertUtil.convert(gwjDepositBusinessService.selectGwjDepositBusinessByBizId(bizId), GwjFundsSplitBusinessDTO.class));
    }

    @GetMapping("/moneyInfo/{bizId}")
    @RequiresPermissions("gwj:deposit:fundsSplit:list")
    @ApiOperation("业务金额")
    public AjaxResult moneyInfo(@PathVariable Long bizId) {
        AjaxResult result = AjaxResult.success();
        result.put("businessMoney", GwjConvertUtil.convert(gwjDepositBusinessMoneyService.selectGwjDepositBusinessMoneyByBizId(bizId), GwjFundsSplitMoneyDTO.class));
        result.put("moneyDetails", GwjConvertUtil.convertList(gwjDepositBusinessDetailService.selectGwjDepositBusinessDetailByBizId(bizId), GwjFundsSplitMoneyDetailDTO.class));
        return result;
    }

    @RequiresPermissions("gwj:basis:init:list")
    @GetMapping("/communityInfo/{bizId}")
    @ApiOperation("小区信息")
    public AjaxResult communityInfo(@PathVariable Long bizId) {
        AjaxResult result = AjaxResult.success();
        GwjDepositBusinessCommunity community = gwjDepositBusinessCommunityService.selectGwjDepositBusinessCommunityByBizId(bizId);
        if (StringUtils.isNotNull(community)) {
            List<GwjDepositBusinessBuild> builds = gwjDepositBusinessBuildService.selectGwjDepositBusinessBuildListByBizCommunityId(community.getBizCommunityId());
            result.put("community", GwjConvertUtil.convert(community, GwjFundsSplitBusinessCommunityDTO.class));
            if (StringUtils.isNotEmpty(builds)) {
                result.put("buildList", GwjConvertUtil.convertList(builds, GwjFundsSplitBusinessBuildDTO.class));
            }
        }
        return result;
    }

    @GetMapping("/publicBuild/list/{bizId}")
    @ApiOperation("公用户楼栋列表")
    public AjaxResult publicBuildList(@PathVariable Long bizId) {
        GwjDepositBusinessBuild gwjDepositBusinessBuild = new GwjDepositBusinessBuild();
        gwjDepositBusinessBuild.setBizId(bizId);
        gwjDepositBusinessBuild.setPublicFlag(GwjConstants.YES);
        return AjaxResult.success(GwjConvertUtil.convertList(gwjDepositBusinessBuildService.selectGwjDepositBusinessBuildList(gwjDepositBusinessBuild), GwjPublicBusinessBuildDTO.class));
    }

    @PostMapping("/publicBuild/create")
    @Log(title = "维修资金分户（初始化）-资金分户-创建公用户楼栋（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("创建公用户楼栋")
    public AjaxResult publicBuildCreate(@RequestBody GwjPublicAccountRequest gwjPublicAccountRequest) {
        gwjFundsSplitBusinessService.createPublicBuild(gwjPublicAccountRequest);
        return AjaxResult.success();
    }

    @PutMapping("/publicBuild/update/{bizId}")
    @Log(title = "维修资金分户（初始化）-资金分户-编辑公用户楼栋（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("编辑公用户楼栋")
    public AjaxResult updatePublicBuild(@PathVariable Long bizId, @RequestBody List<GwjPublicBusinessBuildRequest> gwjDepositBusinessBuilds) {
        //验证是否有操作权限
        gwjDepositBusinessService.checkPermission(bizId);
        if (StringUtils.isNotEmpty(gwjDepositBusinessBuilds)) {
            gwjDepositBusinessBuildService.updateBatchGwjDepositBusinessBuild(GwjConvertUtil.convertList(gwjDepositBusinessBuilds, GwjDepositBusinessBuild.class));
        }
        return AjaxResult.success();
    }

    @DeleteMapping("/publicBuild/delete/{bizId}/{bizBuildIds}")
    @ApiOperation("删除公用户楼栋")
    public AjaxResult deletePublicBuildDelete(@PathVariable("bizId") Long bizId, @PathVariable("bizBuildIds") Long[] bizBuildIds) {
        gwjFundsSplitBusinessService.deletePublicBuild(bizBuildIds, bizId);
        return AjaxResult.success();
    }

    @PostMapping("/publicHouse/create")
    @Log(title = "维修资金分户（初始化）-资金分户-创建公用户房屋（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("创建公用户房屋")
    public AjaxResult publicHouseCreate(@RequestBody GwjPublicAccountRequest gwjPublicAccountRequest) {
        gwjFundsSplitBusinessService.createPublicHouse(gwjPublicAccountRequest);
        return AjaxResult.success();
    }

    @PutMapping("/publicHouse/update")
    @Log(title = "维修资金分户（初始化）-资金分户-编辑公用户房屋（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("编辑公用户房屋")
    public AjaxResult updatePublicHouse(@RequestBody List<GwjPublicBusinessHouseRequest> requests) {
        gwjFundsSplitBusinessService.updatePublicHouse(requests);
        return AjaxResult.success();
    }

    @DeleteMapping("/publicHouse/delete/{bizId}/{bizHouseIds}")
    @Log(title = "维修资金分户（初始化）-资金分户-删除公用户楼栋（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("删除公用户房屋")
    public AjaxResult deletePublicHouseDelete(@PathVariable("bizId") Long bizId, @PathVariable("bizHouseIds") Long[] bizHouseIds) {
        gwjFundsSplitBusinessService.deletePublicHouse(bizHouseIds, bizId);
        return AjaxResult.success();
    }

    @PutMapping("/updateDepositSize")
    @Log(title = "维修资金分户（初始化）-资金分户-业务房屋编辑缴款面积（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("编辑房屋的缴款面积")
    public AjaxResult updateDepositSize(@Validated(GwjFundsSplitBusinessHouseRequest.UpdateDepositSize.class) @RequestBody GwjFundsSplitBusinessHouseRequest request) {
        return toAjax(gwjFundsSplitBusinessService.updateGwjDepositBusinessHouseDepositSize(new GwjDepositBusinessHouse() {{
            setBizId(request.getBizId());
            setBizHouseId(request.getBizHouseId());
            setDepositSize(request.getDepositSize());
        }}));
    }

    @PutMapping("/updateLackMoney")
    @Log(title = "维修资金分户（初始化）-资金分户-业务房屋编辑补差（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("编辑房屋的补差")
    public AjaxResult updateLackMoney(@Validated(GwjFundsSplitBusinessHouseRequest.updateLackMoney.class) @RequestBody GwjFundsSplitBusinessHouseRequest request) {
        return toAjax(gwjFundsSplitBusinessService.updateGwjDepositBusinessHouseLackMoney(new GwjDepositBusinessHouse() {{
            setBizId(request.getBizId());
            setBizHouseId(request.getBizHouseId());
            setLackMoney(request.getLackMoney());
        }}));
    }

    @PutMapping("/updateDepositTime/{bizId}/{depositTime}")
    @Log(title = "维修资金分户（初始化）-资金分户-业务房屋缴存日期存入（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("缴存日期存入")
    public AjaxResult updateDepositTime(@PathVariable("bizId") Long bizId, @PathVariable("depositTime") Date depositTime) {
        gwjFundsSplitBusinessService.updateGwjDepositBusinessHouseDepositTime(bizId, depositTime);
        return AjaxResult.success();
    }

    @PostMapping("/calculateHouse")
    @Log(title = "维修资金分户（初始化）-资金分户-设置计算标准（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("根据标准计算楼栋房屋")
    public AjaxResult calculateHouse(@RequestBody GwjCalculateRequest gwjCalculateRequest) {
        gwjFundsSplitBusinessService.calculateHouse(gwjCalculateRequest);
        return AjaxResult.success();
    }

    @PostMapping("/genFinanceStatement/{bizId}")
    @Log(title = "维修资金分户（初始化）-资金分户-生成财务流水（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("生成财务流水")
    public AjaxResult genFinanceStatement(@PathVariable Long bizId) {
        gwjFundsSplitBusinessService.genFinancialStatement(bizId);
        return AjaxResult.success();
    }

    @PostMapping("/financeCheck/{bizId}")
    @Log(title = "维修资金分户（初始化）-资金分户-财务对账（缴存业务管理模块）", systemName = "gwj")
    @ApiOperation("财务对账")
    public AjaxResult financeCheck(@PathVariable Long bizId) {
        gwjFundsSplitBusinessService.financeCheck(bizId);
        return AjaxResult.success();
    }

    @GetMapping("/accountMain/list")
    @ApiOperation("查询总账流水列表")
    public TableDataInfo accountMainList(@Validated RemoteGwjFinanceAccountMainRequest mainRequest) {
        return gwjDepositBusinessService.selectGwjFinanceAccountMainList(mainRequest);
    }

    @GetMapping("/accountDetail/list")
    @ApiOperation("查询分类账流水列表")
    public TableDataInfo accountDetailList(@Validated RemoteGwjFinanceAccountDetailRequest detailRequest) {
        return gwjDepositBusinessService.selectGwjFinanceAccountDetailList(detailRequest);
    }

    @PostMapping("/allocated/amount")
    @ApiOperation("分摊金额统计")
    public AjaxResult allocatedAmount(@Validated @RequestBody GwjAllocatedAmountRequest request) {
        return AjaxResult.success(gwjFundsSplitBusinessService.allocatedAmount(request));
    }

    @PostMapping("/allocated/amount/screening")
    @ApiOperation("筛选分摊金额统计")
    public AjaxResult allocatedAmountScreening(@Validated @RequestBody GwjAllocatedAmountRequest request) {
        return AjaxResult.success(gwjFundsSplitBusinessService.allocatedAmountScreening(request));
    }

    @GetMapping("/householdRecord/detail/{bizId}")
    @ApiOperation("小区分户清册（头部详情）")
    public AjaxResult communityDetail(@PathVariable Long bizId) {
        return AjaxResult.success(gwjFundsSplitBusinessService.getHouseholdRecordDetail(bizId));
    }

    @GetMapping("/householdRecord/houseList/{bizId}")
    @ApiOperation("小区分户清册(房屋信息)")
    public TableDataInfo houseInfo(@PathVariable Long bizId) {
        GwjFundsSplitBusinessHouseRequest request = new GwjFundsSplitBusinessHouseRequest() {{
            setBizId(bizId);
            setSelectFlag(GwjConstants.YES);
        }};
        startPage();
        return getDataTable(gwjDepositBusinessHouseService.selectGwjDepositBusinessHouseWithOwnerNameList(request));
    }

    @ApiOperation("导出房屋详情列表 含楼栋名称、计算标准名称")
    @Log(title = "维修资金分户（初始化）-资金分户-房屋信息-导出", businessType = BusinessType.EXPORT, systemName = "gwj")
    @PostMapping("/exportHouseInfo")
    public void exportHouseInfo(HttpServletResponse response, @RequestBody GwjFundsSplitBusinessHouseRequest request) {
        if (StringUtils.isNotBlank(request.getBuildCodeStr())) {
            request.setBuildCodes(Convert.toStrArray(request.getBuildCodeStr()));
        }
        List<GwjFundsSplitBusinessHouseDTO> list = gwjDepositBusinessHouseService.selectGwjDepositBusinessHouseWithBuildNameAndCalculateNameList(request);
        ExcelUtil<GwjDepositBusinessHouseExcelVo> util = new ExcelUtil<>(GwjDepositBusinessHouseExcelVo.class);
        util.exportExcel(response, GwjConvertUtil.convertList(list, GwjDepositBusinessHouseExcelVo.class), "房屋数据");
    }

    @ApiOperation("房屋信息导入")
    @Log(title = "维修资金分户（初始化）-资金分户-房屋信息-导入", businessType = BusinessType.IMPORT, systemName = "gwj")
    @PostMapping("/importHouse")
    public AjaxResult importHouse(MultipartFile file, Long bizId) throws Exception {
        if (StringUtils.isNull(bizId)) {
            return AjaxResult.error("请求数据有误[业务ID]不能为空！");
        }
        //验证权限
        gwjDepositBusinessService.checkPermission(bizId);
        if (file.isEmpty()) {
            return AjaxResult.error("导入房屋文件不能为空！");
        }
        if (!checkImportFile(file)) {
            return AjaxResult.error("不是指定的xlsx，xls导入类型文件！");
        }
        String message = gwjFundsSplitBusinessService.importGwjDepositBusinessHouse(file, bizId);
        return AjaxResult.success(message);
    }

    /**
     * 检测导入文件类型是否合规
     *
     * @param file 文件
     * @return /
     */
    private boolean checkImportFile(MultipartFile file) {
        // 检查文件类型
        String type = FileTypeUtils.getExtension(file);
        // 限制的文件类型集合
        return StringUtils.inStringIgnoreCase(type, "xlsx", "xls");
    }
}
